Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REST API query normalization #9190

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

edwin-greene
Copy link
Contributor

Description:
Adds a means to normalize REST API queries.

Related issue(s):

Fixes #9113

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Edwin Greene <[email protected]>
Signed-off-by: Edwin Greene <[email protected]>
Signed-off-by: Edwin Greene <[email protected]>
Signed-off-by: Edwin Greene <[email protected]>
@edwin-greene edwin-greene added enhancement Type: New feature performance rest Area: REST API labels Aug 29, 2024
@edwin-greene edwin-greene added this to the 0.113.0 milestone Aug 29, 2024
@edwin-greene edwin-greene self-assigned this Aug 29, 2024
@edwin-greene edwin-greene linked an issue Aug 29, 2024 that may be closed by this pull request
Copy link

codecov bot commented Aug 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.55%. Comparing base (908fdb7) to head (5c0bdea).
Report is 33 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9190      +/-   ##
============================================
+ Coverage     92.33%   92.55%   +0.22%     
+ Complexity     7600     6997     -603     
============================================
  Files           915      903      -12     
  Lines         30503    29643     -860     
  Branches       3727     3745      +18     
============================================
- Hits          28165    27437     -728     
+ Misses         1506     1442      -64     
+ Partials        832      764      -68     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Edwin Greene <[email protected]>
Signed-off-by: Edwin Greene <[email protected]>
@edwin-greene edwin-greene marked this pull request as ready for review August 31, 2024 18:12
@edwin-greene edwin-greene requested a review from a team August 31, 2024 18:13
Copy link

sonarcloud bot commented Aug 31, 2024

@steven-sheehy steven-sheehy modified the milestones: 0.113.0, 0.114.0 Sep 3, 2024
Copy link
Member

@jascks jascks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this. I can import normalizeRequestQueryParams() into the new response caching middleware and use it to form most of the cache key, along with Accept-Encoding header value.

As far as this PR goes, it can be merged independently as no code is invoked as configured Express middleware or as a query processor.

Comment on lines +29 to +37
input: {
path: '/api/v1/blocks',
query: {
order: 'asc',
unknown: '3',
limit: '5',
},
},
expected: '/api/v1/blocks?limit=5&order=asc&unknown=3',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity and brevity, it would be better if input was simply a string even if you have to parse out the query params from that string in the test. Also, should provide a description that's relayed to jest.

Suggested change
input: {
path: '/api/v1/blocks',
query: {
order: 'asc',
unknown: '3',
limit: '5',
},
},
expected: '/api/v1/blocks?limit=5&order=asc&unknown=3',
description: 'Query parameters are sorted',
input: '/api/v1/blocks?order=asc&unknown=3&limit=5',
expected: '/api/v1/blocks?limit=5&order=asc&unknown=3',

if (_.isUndefined(openApiMap)) {
const openApiObject = getV1OpenApiObject();
const patternMap = getPathParametersPatterns(openApiObject);
openApiMap = new Map();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not assign openApiMap until after it's populated. Use a temporary variable.

* @param patternMap
* @returns {RegExp}
*/
const pathToRegexConverter = (path, patternMap) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of searching 20+ regexes to map it to OpenAPI, we should enable the OpenAPI middleware which already attaches an OpenAPI object to each request. This should be faster than our approach. We should take care to disable request and response validation outside tests though.

@steven-sheehy steven-sheehy modified the milestones: 0.114.0, 0.115.0 Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature performance rest Area: REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add query normalization to support REST API Caching
3 participants